﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NPOI.HSSF.UserModel;
using NPOI.HPSF;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace syc.Produce.Report
{
    public partial class 月份主要原辅料及资金安排计划表 : System.Web.UI.Page
    {
        protected HSSFWorkbook hssfworkbook;
        protected double tggkc;//原料套管库存
        protected double tggN80kc;//原料套管库存
        protected double yggkc;//原料油管库存
        protected double ygjgkc;//原料油管接箍库存
        protected double tgjgkc;//原料套管接箍库存
        protected int cpjgkc;//成品接箍库存
        protected int cpN80jgkc; //成品N80接箍库存
        protected int yglbhkc;//油管螺纹保护环库存
        protected int tglbhkc;//套管螺纹保护环库存

        protected int tggplant;//原料套管计划购进量
        protected int tggN80plant;//原料套管计划购进量
        protected int yggplant;//原料油管计划购进量
        protected int ygjgplant;//原料油管接箍计划购进量
        protected int tgjgplant;//原料套管接箍计划购进量
        protected int cpjgplant;//成品接箍计划购进量
        protected int cpN80jgplant;//成品接箍计划购进量
        protected int yglbhlant;//油管螺纹保护环计划购进量
        protected int tglbhlant;//套管螺纹保护环计划购进量

        protected double tggPrice;//原料套管单价
        protected double tggN80Price;//原料套管单价
        protected double yggPrice;//原料油管单价
        protected double ygjgPrice;//原料油管接箍单价
        protected double tgjgPrice;//原料套管接箍单价
        protected double cpjgPrice;//成品接箍单价
        protected double cpN80jgPrice;//成品接箍单价

        protected double  yglbhPrice;//油管螺纹保护环单价
        protected double tglbhPrice;//套管螺纹保护环单价

        protected int 稀释剂plant;//稀释剂计划购进量
        protected int 黑色油漆plant;//黑色油漆计划购进量
        protected int 打包带plant;//油漆计划购进量
        protected double 螺纹脂plant;//螺纹脂计划购进量
        protected double 白色环漆plant;//白色环漆计划购进量
        protected double 接箍漆plant;//接箍漆计划购进量
        protected int 白墨plant;//白墨计划购进量
        protected int 草支垫plant;//草支垫计划购进量

        protected double 稀释剂库存;//稀释剂库存
        protected double 黑色油漆;//黑色油漆库存
        protected double 打包带库存;//油漆库存
        protected double 螺纹脂库存;//螺纹脂库存
        protected double 白色环漆库存;//白色环漆库存
        protected double 接箍漆库存;//接箍漆库存
        protected int 白墨库存;//白墨库存
        protected int 草支垫库存;//草支垫库存

        protected double 稀释剂Price;//稀释剂单价
        protected double 黑色油漆Price;//黑色油漆单价
        protected double 打包带Price;//油漆单价
        protected double 螺纹脂Price;//螺纹脂单价
        protected double 白色环漆Price;//白色环漆单价
        protected double 接箍漆Price;//接箍漆单价
        protected double 白墨Price;//白墨单价
        protected double 草支垫Price;//草支垫单价

        protected double 套管全月支付;
        protected double 套管N80全月支付;
        protected double 油管全月支付;
        protected double 油管接箍管全月支付;
        protected double 套管接箍管全月支付;
        protected double 成品接箍全月支付;
        protected double 成品N80接箍全月支付;

        protected double 油管螺纹保护器全月支付;
        protected double 套管螺纹保护器全月支付;
        protected double 稀释剂全月支付;
        protected double 油漆全月支付;
        protected double 油品全月支付;
        protected double 打包带全月支付;
        protected double 螺纹脂全月支付;
        protected double 色环漆全月支付;
        protected double 接箍漆全月支付;
        protected double 白墨全月支付;
        protected double 草支垫全月支付;
        protected double 其它全月支付;
        protected double 合计;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.Year0.SelectedValue = DateTime.Today.Year.ToString();
                this.Month0.SelectedValue = DateTime.Today.Month.ToString();
                ((TextBox)this.FindControl("R" + 1)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 1)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 2)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 2)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 3)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 3)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 4)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 4)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 5)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 5)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 6)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 6)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 7)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 7)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 8)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 8)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 9)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 9)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 10)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 10)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 11)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 11)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 12)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 12)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 13)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 13)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 14)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 14)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 15)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 15)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 16)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 16)).CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 17)).ReadOnly = true;
                ((TextBox)this.FindControl("R" + 17)).CssClass = "blank_center";
                //((TextBox)this.FindControl("R" + 18)).ReadOnly = true;
                //((TextBox)this.FindControl("R" + 18)).CssClass = "blank_center";
                Button_Query_Click(null, null);
            }     
        }

        protected void Button_Query_Click(object sender, EventArgs e)
        {
            
            ((TextBox)this.FindControl("R" + 1)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 1)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 2)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 2)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 3)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 3)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 4)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 4)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 5)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 5)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 6)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 6)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 7)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 7)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 8)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 8)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 9)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 9)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 10)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 10)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 11)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 11)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 12)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 12)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 13)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 13)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 14)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 14)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 15)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 15)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 16)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 16)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 17)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 17)).CssClass = "blank_center";
            //((TextBox)this.FindControl("R" + 18)).ReadOnly = true;
            //((TextBox)this.FindControl("R" + 18)).CssClass = "blank_center";
            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            Cmd.CommandText = "select count(*) from 生产处月原料采购计划 where 年度=" + this.Year0.SelectedValue + " and 月份=" + this.Month0.Text + "";
            this.Message.Text = "·准备就绪";
            if ((int)Cmd.ExecuteScalar()== 0)
            {
                //this.Button_Plan_In.Text = "录入油品及其它支付金额";
                //this.Button_Plan_In.Visible = true;
                //this.Button_Save0.Visible = true;
            }
            else
            {
                //this.Button_Plan_In.Visible = true;
                //this.Button_Plan_In.Text = "修改油品及其它支付金额";
                //this.Button_Save0.Visible = true;
                this.R1.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 1)).ReadOnly = true;
                this.R2.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 2)).ReadOnly = true;
                this.R3.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 3)).ReadOnly = true;
                this.R4.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 4)).ReadOnly = true;
                this.R5.CssClass = "blank_center";
                ((TextBox)this.FindControl("R" + 5)).ReadOnly = true;
            }
            string sql0 = @"       
            declare @ym datetime         

            declare @油管光管实有库存 float
            declare @套管光管实有库存 float  
            declare @套管N80光管实有库存 float  
            declare @油管接箍管实有库存 float
            declare @套管接箍管实有库存 float
            declare @套管成品接箍实有库存 int
            declare @套管N80成品接箍实有库存 int         
            
            select @油管光管实有库存=[dbo].[原料实时库存](@年度,@月份,1) 
            select @套管光管实有库存=[dbo].[原料实时库存](@年度,@月份,2) 
            select @套管N80光管实有库存=[dbo].[原料实时库存](@年度,@月份,102) 
            select @油管接箍管实有库存=[dbo].[原料实时库存](@年度,@月份,3) 
            select @套管接箍管实有库存=[dbo].[原料实时库存](@年度,@月份,4) 
            select @套管成品接箍实有库存=[dbo].[原料实时库存](@年度,@月份,6) 
            select @套管N80成品接箍实有库存=[dbo].[原料实时库存](@年度,@月份,106) 

            select @油管光管实有库存,@套管光管实有库存,@油管接箍管实有库存,@套管接箍管实有库存,@套管成品接箍实有库存,@套管N80光管实有库存,@套管N80成品接箍实有库存";         
            sql0 = sql0.Replace("@年度", this.Year0.SelectedValue);
            sql0 = sql0.Replace("@月份", this.Month0.SelectedValue);
            Cmd.CommandText = sql0;
            SqlDataReader Reader = Cmd.ExecuteReader();
            //实有库存
            if (Reader.Read())
            {
                yggkc = Reader.GetDouble(0);
                tggkc = Reader.GetDouble(1);
                ygjgkc = Reader.GetDouble(2);
                tgjgkc = Reader.GetDouble(3);
                cpjgkc = Reader.GetInt32(4);
                tggN80kc = Reader.GetDouble(5);
                cpN80jgkc = Reader.GetInt32(6);
            }
            Reader.Close();
           string sql  = @"       
            declare @ym datetime
            declare @yglbhkc int
            declare @tglbhkc int  
            declare @稀释剂库存1 float 
            declare @稀释剂库存2 float 
            declare @稀释剂库存 float 
            declare @黑色油漆库存 float;
            declare @打包带库存 float;
            declare @螺纹脂库存 float;
            declare @白色环漆库存 float;
            declare @接箍漆库存 float;
            declare @白墨库存 int;
            declare @草支垫库存 int;  
            select @ym=(select 截止日期 from  生产月设置 where  分厂=0 and 年度=@年份 and 月份=@月份)  
            select @yglbhkc=isnull(sum(数量),0) from 材料入出库 where 材料ID=0700000001 and 日期<=@ym 
            select @tglbhkc=isnull(sum(数量),0) from 材料入出库 where 材料ID=0700000002 and 日期<=@ym
            select @稀释剂库存1=isnull(sum(数量),0) from 材料入出库 where 材料ID=0301000003 and 日期<=@ym
            select @稀释剂库存2=isnull(sum(数量),0) from 材料入出库 where 材料ID=0301000004 and 日期<=@ym
            select @稀释剂库存=@稀释剂库存1+@稀释剂库存2
            select @黑色油漆库存=isnull(sum(数量),0) from 材料入出库 where 材料ID=0301000001 and 日期<=@ym
            select @打包带库存=isnull(sum(数量),0) from 材料入出库 where 材料ID=0401000001 and 日期<=@ym
            select @螺纹脂库存=isnull(sum(数量),0) from 材料入出库 where 材料ID=0302000001 and 日期<=@ym
            select @白色环漆库存=isnull(sum(数量),0) from 材料入出库 where 材料ID=0301000011 and 日期<=@ym
            select @接箍漆库存=isnull(sum(数量),0) from 材料入出库 where 材料ID=0300000007 and 日期<=@ym
            select @白墨库存=isnull(sum(数量),0) from 材料入出库 where 材料ID=0303000007 and 日期<=@ym
            select @草支垫库存=isnull(sum(数量),0) from 材料入出库 where 材料ID=0700000003 and 日期<=@ym

            select @yglbhkc,@tglbhkc,@稀释剂库存,@黑色油漆库存,@打包带库存,@螺纹脂库存,@白色环漆库存,@接箍漆库存,@白墨库存,@草支垫库存";
            sql = sql.Replace("@年份",this.Year0.SelectedValue);
            sql = sql.Replace("@月份", this.Month0.SelectedValue);
            Cmd.CommandText = sql;
            Reader = Cmd.ExecuteReader();
            //实有库存
            if (Reader.Read())
            {
                yglbhkc = Reader.GetInt32(0);
                tglbhkc = Reader.GetInt32(1);
                稀释剂库存 = Reader.GetDouble(2);
                黑色油漆 = Reader.GetDouble(3);
                打包带库存 = Reader.GetDouble(4);
                螺纹脂库存 = Reader.GetDouble(5);
                白色环漆库存 = Reader.GetDouble(6);
                接箍漆库存 = Reader.GetDouble(7);
                白墨库存 = Reader.GetInt32(8);
                草支垫库存 = Reader.GetInt32(9);
            }
            Reader.Close();
            //计划购进
            string sqlPlant = @"      
          
            declare @油管光管 int
            declare @套管光管 int  
            declare @套管N80光管 int 
            declare @油管接箍光管 int
            declare @套管接箍光管 int
            declare @套管成品接箍 int
            declare @套管N80成品接箍 int
          
            declare @套管螺纹保护环 int
            declare @油管螺纹保护环 int
            declare @稀释剂1 int
            declare @油漆1 int
            declare @稀释剂2 int
            declare @油漆2 int
            declare @稀释剂 int
            declare @油漆 int
            declare @打包带 int 
            declare @螺纹脂 float
            declare @色环漆 float
            declare @接箍漆 float
            declare @白墨 int
            declare @草支垫 int
            
            select @油管光管=isnull(sum(计划购进量),0) from 生产处月原料采购计划 where 原料ID=1 and 年度=@年度 and 月份=@月份          
            select @套管光管=isnull(sum(计划购进量),0) from 生产处月原料采购计划  where 原料ID=2 and 年度=@年度 and 月份=@月份  
            select @套管N80光管=isnull(sum(计划购进量),0) from 生产处月原料采购计划  where 原料ID=102 and 年度=@年度 and 月份=@月份  
            select @油管接箍光管=isnull(sum(计划购进量),0) from 生产处月原料采购计划 where 原料ID=3 and 年度=@年度 and 月份=@月份          
            select @套管接箍光管=isnull(sum(计划购进量),0) from 生产处月原料采购计划 where 原料ID=4 and 年度=@年度 and 月份=@月份 
            select @套管成品接箍=isnull(sum(计划购进量),0) from 生产处月原料采购计划 where 原料ID=6 and 年度=@年度 and 月份=@月份
            select @套管N80成品接箍=isnull(sum(计划购进量),0) from 生产处月原料采购计划 where 原料ID=106 and 年度=@年度 and 月份=@月份
            
            select @套管螺纹保护环=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0700000002 and 年度=@年度 and 月份=@月份 
            select @油管螺纹保护环=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0700000001 and 年度=@年度 and 月份=@月份
            select @稀释剂1=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0301000003 and 年度=@年度 and 月份=@月份
            select @稀释剂2=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0301000004 and 年度=@年度 and 月份=@月份
            select @油漆1=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0301000001 and 年度=@年度 and 月份=@月份
            select @油漆2=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0301000002 and 年度=@年度 and 月份=@月份 
            select @稀释剂=@稀释剂1+@稀释剂2
            select @油漆=@油漆1+@油漆2
            select @打包带=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0401000001 and 年度=@年度 and 月份=@月份 
            select @螺纹脂=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0302000001 and 年度=@年度 and 月份=@月份
            select @色环漆=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0301000006 and 年度=@年度 and 月份=@月份
            select @接箍漆=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0301000005 and 年度=@年度 and 月份=@月份 
            select @白墨=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0303000007 and 年度=@年度 and 月份=@月份 
            select @草支垫=isnull(sum(计划购进量),0) from 辅料采购计划0 where 辅料ID=0700000003 and 年度=@年度 and 月份=@月份             
            select @油管光管,@套管光管,@油管接箍光管,@套管接箍光管,@套管成品接箍,@套管螺纹保护环,@油管螺纹保护环,@稀释剂,@油漆,@打包带,@螺纹脂,@色环漆,@接箍漆,@白墨,@草支垫,@套管N80光管,@套管N80成品接箍
            
";          
            sqlPlant = sqlPlant.Replace("@年度", this.Year0.SelectedValue);
            sqlPlant = sqlPlant.Replace("@月份", this.Month0.SelectedValue);
            Cmd.CommandText = sqlPlant;
            Reader = Cmd.ExecuteReader();
            //实有库存
            if (Reader.Read())
            {
                yggplant= Reader.GetInt32(0);
                tggplant= Reader.GetInt32(1);
                ygjgplant= Reader.GetInt32(2);
                tgjgplant= Reader.GetInt32(3);
                cpjgplant= Reader.GetInt32(4);

                tglbhlant = Reader.GetInt32(5);
                yglbhlant = Reader.GetInt32(6);                
                稀释剂plant= Reader.GetInt32(7);
                黑色油漆plant= Reader.GetInt32(8);
                油品全月支付 = 0;
                打包带plant= Reader.GetInt32(9);
                螺纹脂plant = Reader.GetDouble(10);
                白色环漆plant = Reader.GetDouble(11);
                接箍漆plant= Reader.GetDouble(12);
                白墨plant= Reader.GetInt32(13);
                草支垫plant = Reader.GetInt32(14);
                tggN80plant = Reader.GetInt32(15);
                cpN80jgplant = Reader.GetInt32(16);

                其它全月支付 = 0;
            }
            Reader.Close();
            this.R1.Text = tggplant.ToString();
            this.R2.Text = tggN80plant.ToString();
            this.R3.Text = yggplant.ToString();
            this.R4.Text = ygjgplant.ToString();
            this.R5.Text = tgjgplant.ToString();
            this.R6.Text = cpjgplant.ToString();
            this.R7.Text = tglbhlant.ToString();
            this.R8.Text = yglbhlant.ToString();
            this.R9.Text = 稀释剂plant.ToString();
            this.R10.Text = 黑色油漆plant.ToString();
            this.R11.Text = 油品全月支付.ToString();
            this.R12.Text = 打包带plant.ToString();
            this.R13.Text = 螺纹脂plant.ToString();
            this.R14.Text = 白色环漆plant.ToString();
            this.R15.Text = 接箍漆plant.ToString();
            this.R16.Text = 白墨plant.ToString();
            this.R17.Text = 草支垫plant.ToString();
      
            //单价
//            string sql1 = @" 
//            declare @yc datetime   
//            declare @ym datetime 
//            declare @油管光管单价 float
//            declare @套管光管单价 float  
//            declare @油管接箍单价 float
//            declare @套管接箍单价 float     
//            declare @套管成品接箍单价 float     
//            select @yc=起始日期,@ym=截止日期 from  生产月设置 where  分厂=0 and 年度=@年份 and 月份=@月份
//            select @油管光管单价=isnull(avg(单价),0) from  原料采购合同 where 原料ID=1 and 年度=@年度 and 季度=@季度 and 签订日期 between @yc and @ym 
//            select @套管光管单价=isnull(avg(单价),0) from  原料采购合同 where 原料ID=2 and 年度=@年度 and 季度=@季度 and 签订日期 between @yc and @ym 
//            select @油管接箍单价=isnull(avg(单价),0) from  原料采购合同 where 原料ID=3 and 年度=@年度 and 季度=@季度 and 签订日期 between @yc and @ym 
//            select @套管接箍单价=isnull(avg(单价),0) from  原料采购合同 where 原料ID=4 and 年度=@年度 and 季度=@季度 and 签订日期 between @yc and @ym
//            select @套管成品接箍单价=isnull(avg(单价),0) from  原料采购合同 where 原料ID=6 and 季度=@季度 and 签订日期 between @yc and @ym
//            
//            select @油管光管单价,@套管光管单价,@油管接箍单价,@套管接箍单价,@套管成品接箍单价";
//            sql1 = sql1.Replace("@年份", this.Year0.SelectedValue);
//            sql1 = sql1.Replace("@月份", this.Month0.SelectedValue);
//            sql1 = sql1.Replace("@年度", this.Year0.SelectedValue);
//            if (this.Month0.SelectedValue == "1" || this.Month0.SelectedValue == "2" || this.Month0.SelectedValue == "3")
//            {
//                sql1 = sql1.Replace("@季度", "1");
//            }
//            if (this.Month0.SelectedValue == "4" || this.Month0.SelectedValue == "5" || this.Month0.SelectedValue == "6")
//            {
//                sql1 = sql1.Replace("@季度", "2");
//            }
//            if (this.Month0.SelectedValue == "7" || this.Month0.SelectedValue == "8" || this.Month0.SelectedValue == "9")
//            {
//                sql1 = sql1.Replace("@季度", "3");
//            }
//            if (this.Month0.SelectedValue == "10" || this.Month0.SelectedValue == "11" || this.Month0.SelectedValue == "12")
//            {
//                sql1 = sql1.Replace("@季度", "4");
//            }
            string sql1 = @" 
            declare @yc datetime   
            declare @ym datetime 
            declare @油管光管单价 float
            declare @套管光管单价 float  
            declare @套管N80光管单价 float 
            declare @油管接箍单价 float
            declare @套管接箍单价 float     
            declare @套管成品接箍单价 float 
            declare @套管N80成品接箍单价 float 

            select @油管光管单价=isnull(avg(单价),0) from  生产处月原料采购计划 where 原料ID=1 and 年度=@年度 and 月份=@月份  
            select @套管光管单价=isnull(avg(单价),0) from  生产处月原料采购计划 where 原料ID=2 and 年度=@年度 and 月份=@月份  
            select @套管N80光管单价=isnull(avg(单价),0) from  生产处月原料采购计划 where 原料ID=102 and 年度=@年度 and 月份=@月份  
            select @油管接箍单价=isnull(avg(单价),0) from  生产处月原料采购计划 where 原料ID=3 and 年度=@年度 and 月份=@月份  
            select @套管接箍单价=isnull(avg(单价),0) from  生产处月原料采购计划 where 原料ID=4 and 年度=@年度 and 月份=@月份 
            select @套管成品接箍单价=isnull(avg(单价),0) from  生产处月原料采购计划 where 原料ID=6 and  年度=@年度 and 月份=@月份 
            select @套管N80成品接箍单价=isnull(avg(单价),0) from  生产处月原料采购计划 where 原料ID=106 and  年度=@年度 and 月份=@月份 
            select @油管光管单价,@套管光管单价,@油管接箍单价,@套管接箍单价,@套管成品接箍单价,@套管N80光管单价,@套管N80成品接箍单价 ";
            sql1 = sql1.Replace("@年度", this.Year0.SelectedValue);
            sql1 = sql1.Replace("@月份", this.Month0.SelectedValue);
            Cmd.CommandText = sql1;
            Reader = Cmd.ExecuteReader();
            
            if (Reader.Read())
            {
                yggPrice = Reader.GetDouble(0);
                tggPrice = Reader.GetDouble(1);
                ygjgPrice = Reader.GetDouble(2);
                tgjgPrice = Reader.GetDouble(3);
                cpjgPrice = Reader.GetDouble(4);
                tggN80Price = Reader.GetDouble(5);
                cpN80jgPrice = Reader.GetDouble(6);
            }
            Reader.Close();
//            string sql2 = @"            
//            declare @yglbhPrice float
//            declare @tglbhPrice float
//            declare @稀释剂Price float
//            declare @黑色油漆Price float
//            declare @打包带Price float
//            declare @螺纹脂Price float
//            declare @白色环漆Price float
//            declare @接箍漆Price float
//            declare @白墨Price float
//            declare @草支垫Price float
//        
//            select @yglbhPrice=isnull(Avg(单价),0) from 辅料采购合同 where 辅料ID=(select ID from 材料 where 品名='油管螺纹保护环') and  年度=@年度 and 月份=@月份
//            select @tglbhPrice=isnull(Avg(单价),0) from 辅料采购合同 where 辅料ID=(select ID from 材料 where 品名='套管螺纹保护环') and  年度=@年度 and 月份=@月份
//            select @稀释剂Price=isnull(Avg(单价),0) from 辅料采购合同 where 辅料ID=(select ID from 材料 where 品名='稀释剂') and 年度=@年度 and 月份=@月份
//            select @黑色油漆Price=isnull(Avg(单价),0) from 辅料采购合同 where 辅料ID=(select ID from 材料 where 品名='油漆') and 年度=@年度 and 月份=@月份
//            select @打包带Price=isnull(Avg(单价),0) from 辅料采购合同 where 辅料ID=(select ID from 材料 where 品名='打包带') and 年度=@年度 and 月份=@月份
//            select @螺纹脂Price=isnull(Avg(单价),0) from 辅料采购合同 where 辅料ID=(select ID from 材料 where 品名='螺纹脂') and 年度=@年度 and 月份=@月份
//            select @白色环漆Price=isnull(Avg(单价),0) from 辅料采购合同 where 辅料ID=(select ID from 材料 where 品名='色环漆') and 年度=@年度 and 月份=@月份
//            select @接箍漆Price=isnull(Avg(单价),0) from 辅料采购合同 where 辅料ID=(select ID from 材料 where 品名='接箍漆') and 年度=@年度 and 月份=@月份
//            select @白墨Price=isnull(Avg(单价),0) from 辅料采购合同 where 辅料ID=(select ID from 材料 where 品名='白墨') and 年度=@年度 and 月份=@月份
//            select @草支垫Price=isnull(Avg(单价),0) from 辅料采购合同 where 辅料ID=(select ID from 材料 where 品名='草支垫') and 年度=@年度 and 月份=@月份
//            
//            select @yglbhPrice,@tglbhPrice,@稀释剂Price,@黑色油漆Price,@打包带Price,@螺纹脂Price,@白色环漆Price,@接箍漆Price,@白墨Price,@草支垫Price";
            string sql2 = @" 
            declare @yglbhPrice float
            declare @tglbhPrice float
            declare @稀释剂Price float
            declare @黑色油漆Price float
            declare @打包带Price float
            declare @螺纹脂Price float
            declare @白色环漆Price float
            declare @接箍漆Price float
            declare @白墨Price float
            declare @草支垫Price float

            select @yglbhPrice=isnull(Avg(单价),0) from 辅料采购计划0 where 辅料ID=0700000001 and  年度=@年度 and 月份=@月份
            select @tglbhPrice=isnull(Avg(单价),0) from 辅料采购计划0 where 辅料ID=0700000002 and  年度=@年度 and 月份=@月份
            select @稀释剂Price=isnull(Avg(单价),0) from 辅料采购计划0 where 辅料ID=(select ID from 材料 where 品名 like '%稀释剂') and 年度=@年度 and 月份=@月份
            select @黑色油漆Price=isnull(Avg(单价),0) from 辅料采购计划0 where 辅料ID=(select ID from 材料 where 品名 like '保护涂料') and 年度=@年度 and 月份=@月份
            select @打包带Price=isnull(Avg(单价),0) from 辅料采购计划0 where 辅料ID=0401000001 and 年度=@年度 and 月份=@月份
            select @螺纹脂Price=isnull(Avg(单价),0) from 辅料采购计划0 where 辅料ID=0302000001 and 年度=@年度 and 月份=@月份
            select @白色环漆Price=isnull(Avg(单价),0) from 辅料采购计划0 where 辅料ID=0301000011  and 年度=@年度 and 月份=@月份
            select @接箍漆Price=isnull(Avg(单价),0) from 辅料采购计划0 where 辅料ID=0300000007 and 年度=@年度 and 月份=@月份
            select @白墨Price=isnull(Avg(单价),0) from 辅料采购计划0 where 辅料ID=0303000007  and 年度=@年度 and 月份=@月份
            select @草支垫Price=isnull(Avg(单价),0) from 辅料采购计划0 where 辅料ID=0700000003 and 年度=@年度 and 月份=@月份
            select @yglbhPrice,@tglbhPrice,@稀释剂Price,@黑色油漆Price,@打包带Price,@螺纹脂Price,@白色环漆Price,@接箍漆Price,@白墨Price,@草支垫Price
             ";
            sql2 = sql2.Replace("@年度", this.Year0.SelectedValue);
            sql2 = sql2.Replace("@月份", this.Month0.SelectedValue);
     
            Cmd.CommandText = sql2;
            Reader = Cmd.ExecuteReader();
            if (Reader.Read())
            {
                yglbhPrice = Reader.GetDouble(0);
                tglbhPrice = Reader.GetDouble(1);
                稀释剂Price = Reader.GetDouble(2);
                黑色油漆Price = Reader.GetDouble(3);
                打包带Price = Reader.GetDouble(4);
                螺纹脂Price = Reader.GetDouble(5);
                白色环漆Price = Reader.GetDouble(6);
                接箍漆Price = Reader.GetDouble(7);
                白墨Price = Reader.GetDouble(8);
                草支垫Price = Reader.GetDouble(9);
            }
            Reader.Close();
           
            套管全月支付 = tggPrice * double.Parse(this.R1.Text);
            套管N80全月支付 = tggN80Price * double.Parse(this.R2.Text);
            油管全月支付 = yggPrice * double.Parse(this.R3.Text);
            油管接箍管全月支付 = ygjgPrice * double.Parse(this.R4.Text);
            套管接箍管全月支付 = tgjgPrice * double.Parse(this.R5.Text);
            成品接箍全月支付 = cpjgPrice * double.Parse(this.R6.Text);
            油管螺纹保护器全月支付 = yglbhPrice * double.Parse(this.R7.Text);
            套管螺纹保护器全月支付 = tglbhPrice * double.Parse(this.R8.Text);
            稀释剂全月支付 = 稀释剂Price * double.Parse(this.R9.Text);
            油漆全月支付 = 黑色油漆Price * double.Parse(this.R10.Text);
            
            打包带全月支付 = 打包带Price * double.Parse(this.R12.Text);
            螺纹脂全月支付 = 螺纹脂Price * double.Parse(this.R13.Text);
            色环漆全月支付 = 白色环漆Price * double.Parse(this.R14.Text);
            接箍漆全月支付 = 接箍漆Price * double.Parse(this.R15.Text);
            白墨全月支付 = 白墨Price * double.Parse(this.R16.Text);
            草支垫全月支付 = 草支垫Price * double.Parse(this.R17.Text);

            成品N80接箍全月支付 = cpN80jgPrice * cpN80jgplant;
          
            Conn.Close();
            合计 = 套管N80全月支付+套管全月支付 + 油管全月支付 + 油管接箍管全月支付 + 套管接箍管全月支付 + 成品接箍全月支付 + 油管螺纹保护器全月支付 + 套管螺纹保护器全月支付 + 稀释剂全月支付 + 油漆全月支付  + 打包带全月支付 +
                螺纹脂全月支付 + 色环漆全月支付 + 接箍漆全月支付 + 白墨全月支付 + 草支垫全月支付 + 成品N80接箍全月支付;
          
            Reader.Dispose();
            Cmd.Dispose();
            Conn.Dispose();
        }
        protected void WriteToFile()
        {
       
            Response.ContentType = "application/ms-excel";
            Response.AddHeader("content-disposition", "attachment; filename=\"" + DateTime.Now.ToShortDateString() + ".xls\"");
            hssfworkbook.Write(Response.OutputStream);
        }

        protected void InitializeWorkbook()
        {

            FileStream file = new FileStream(HttpContext.Current.Server.MapPath("/Produce/模板/主要原辅料及资金安排计划表.xls"), FileMode.Open, FileAccess.Read);

            hssfworkbook = new HSSFWorkbook(file);

            DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
            dsi.Company = "主要原辅料及资金安排计划";
            hssfworkbook.DocumentSummaryInformation = dsi;

            SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
            si.Subject = "报表";
            si.Title = "主要原辅料及资金安排计划";
            hssfworkbook.SummaryInformation = si;
        }
        protected void Button_Save_Click(object sender, EventArgs e)
        {

            InitializeWorkbook();
            HSSFSheet sheet1 = hssfworkbook.GetSheet("主要原辅料及资金安排计划");
            Button_Query_Click(null, null);
            sheet1.GetRow(0).GetCell(0).SetCellValue(this.Year0.SelectedValue + "年" + this.Month0.SelectedValue + "月份主要原材料、辅助材料及资金安排计划");
            sheet1.GetRow(2).GetCell(0).SetCellValue(this.Month0.SelectedItem.Text + "月份主要原、辅料及资金安排计划表");

            sheet1.GetRow(5).GetCell(3).SetCellValue(tggkc);
            sheet1.GetRow(5).GetCell(4).SetCellValue(this.R1.Text);
            sheet1.GetRow(5).GetCell(5).SetCellValue(tggPrice);
            sheet1.GetRow(5).GetCell(6).SetCellValue(套管全月支付);

            sheet1.GetRow(6).GetCell(3).SetCellValue(tggN80kc);
            sheet1.GetRow(6).GetCell(4).SetCellValue(this.R2.Text);
            sheet1.GetRow(6).GetCell(5).SetCellValue(tggN80Price);
            sheet1.GetRow(6).GetCell(6).SetCellValue(套管N80全月支付);

            sheet1.GetRow(7).GetCell(3).SetCellValue(yggkc);
            sheet1.GetRow(7).GetCell(4).SetCellValue(this.R3.Text);
            sheet1.GetRow(7).GetCell(5).SetCellValue(yggPrice);
            sheet1.GetRow(7).GetCell(6).SetCellValue(油管全月支付);

            sheet1.GetRow(8).GetCell(3).SetCellValue(ygjgkc);
            sheet1.GetRow(8).GetCell(4).SetCellValue(this.R4.Text);
            sheet1.GetRow(8).GetCell(5).SetCellValue(ygjgPrice);
            sheet1.GetRow(8).GetCell(6).SetCellValue(油管接箍管全月支付);

            sheet1.GetRow(9).GetCell(3).SetCellValue(tgjgkc);
            sheet1.GetRow(9).GetCell(4).SetCellValue(this.R5.Text);
            sheet1.GetRow(9).GetCell(5).SetCellValue(tgjgPrice);
            sheet1.GetRow(9).GetCell(6).SetCellValue(套管接箍管全月支付);

            sheet1.GetRow(10).GetCell(3).SetCellValue(cpjgkc);
            sheet1.GetRow(10).GetCell(4).SetCellValue(this.R6.Text);
            sheet1.GetRow(10).GetCell(5).SetCellValue(cpjgPrice);
            sheet1.GetRow(10).GetCell(6).SetCellValue(成品接箍全月支付);

            sheet1.GetRow(11).GetCell(3).SetCellValue(tglbhkc);
            sheet1.GetRow(11).GetCell(4).SetCellValue(this.R7.Text);
            sheet1.GetRow(11).GetCell(5).SetCellValue(tglbhPrice);
            sheet1.GetRow(11).GetCell(6).SetCellValue(套管螺纹保护器全月支付);

            sheet1.GetRow(12).GetCell(3).SetCellValue(yglbhkc);
            sheet1.GetRow(12).GetCell(4).SetCellValue(this.R8.Text);
            sheet1.GetRow(12).GetCell(5).SetCellValue(yglbhPrice);
            sheet1.GetRow(12).GetCell(6).SetCellValue(油管螺纹保护器全月支付);

            sheet1.GetRow(13).GetCell(3).SetCellValue(稀释剂库存);
            sheet1.GetRow(13).GetCell(4).SetCellValue(this.R9.Text);
            sheet1.GetRow(13).GetCell(5).SetCellValue(稀释剂Price);
            sheet1.GetRow(13).GetCell(6).SetCellValue(稀释剂全月支付);

            sheet1.GetRow(14).GetCell(3).SetCellValue(黑色油漆);
            sheet1.GetRow(14).GetCell(4).SetCellValue(this.R10.Text);
            sheet1.GetRow(14).GetCell(5).SetCellValue(黑色油漆Price);
            sheet1.GetRow(14).GetCell(6).SetCellValue(油漆全月支付);

            sheet1.GetRow(15).GetCell(3).SetCellValue("");
            sheet1.GetRow(15).GetCell(4).SetCellValue("");
            sheet1.GetRow(15).GetCell(5).SetCellValue("");
            sheet1.GetRow(15).GetCell(6).SetCellValue(this.R11.Text);

            sheet1.GetRow(16).GetCell(3).SetCellValue(打包带库存);
            sheet1.GetRow(16).GetCell(4).SetCellValue(this.R12.Text);
            sheet1.GetRow(16).GetCell(5).SetCellValue(打包带Price);
            sheet1.GetRow(16).GetCell(6).SetCellValue(打包带全月支付);

            sheet1.GetRow(17).GetCell(3).SetCellValue(螺纹脂库存);
            sheet1.GetRow(17).GetCell(4).SetCellValue(this.R13.Text);
            sheet1.GetRow(17).GetCell(5).SetCellValue(螺纹脂Price);
            sheet1.GetRow(17).GetCell(6).SetCellValue(螺纹脂全月支付);

            sheet1.GetRow(18).GetCell(3).SetCellValue(白色环漆库存);
            sheet1.GetRow(18).GetCell(4).SetCellValue(this.R14.Text);
            sheet1.GetRow(18).GetCell(5).SetCellValue(白色环漆Price);
            sheet1.GetRow(18).GetCell(6).SetCellValue(色环漆全月支付);

            sheet1.GetRow(19).GetCell(3).SetCellValue(接箍漆库存);
            sheet1.GetRow(19).GetCell(4).SetCellValue(this.R15.Text);
            sheet1.GetRow(19).GetCell(5).SetCellValue(接箍漆Price);
            sheet1.GetRow(19).GetCell(6).SetCellValue(接箍漆全月支付);

            sheet1.GetRow(20).GetCell(3).SetCellValue(白墨库存);
            sheet1.GetRow(20).GetCell(4).SetCellValue(this.R16.Text);
            sheet1.GetRow(20).GetCell(5).SetCellValue(白墨Price);
            sheet1.GetRow(20).GetCell(6).SetCellValue(白墨全月支付);

            sheet1.GetRow(21).GetCell(3).SetCellValue(草支垫库存);
            sheet1.GetRow(21).GetCell(4).SetCellValue(this.R17.Text);
            sheet1.GetRow(21).GetCell(5).SetCellValue(草支垫Price);
            sheet1.GetRow(21).GetCell(6).SetCellValue(草支垫全月支付);


            sheet1.GetRow(23).GetCell(3).SetCellValue("");
            sheet1.GetRow(23).GetCell(4).SetCellValue("");
            sheet1.GetRow(23).GetCell(5).SetCellValue("");
            sheet1.GetRow(23).GetCell(6).SetCellValue(合计);     

            WriteToFile();
            Response.End();
        }    

        protected void Month0_SelectedIndexChanged(object sender, EventArgs e)
        {
            Button_Plan_In.Visible = false;
            this.Button_Save0.Visible = false;
            ((TextBox)this.FindControl("R" + 1)).Text = "0";
            ((TextBox)this.FindControl("R" + 1)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 1)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 2)).Text = "0";
            ((TextBox)this.FindControl("R" + 2)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 2)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 3)).Text = "0";
            ((TextBox)this.FindControl("R" + 3)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 3)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 4)).Text = "0";
            ((TextBox)this.FindControl("R" + 4)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 4)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 5)).Text = "0";
            ((TextBox)this.FindControl("R" + 5)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 5)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 6)).Text = "0";
            ((TextBox)this.FindControl("R" + 6)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 6)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 7)).Text = "0";
            ((TextBox)this.FindControl("R" + 7)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 7)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 8)).Text = "0";
            ((TextBox)this.FindControl("R" + 8)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 8)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 9)).Text = "0";
            ((TextBox)this.FindControl("R" + 9)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 9)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 10)).Text = "0";
            ((TextBox)this.FindControl("R" + 10)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 10)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 11)).Text = "0";
            ((TextBox)this.FindControl("R" + 11)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 11)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 12)).Text = "0";
            ((TextBox)this.FindControl("R" + 12)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 12)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 13)).Text = "0";
            ((TextBox)this.FindControl("R" + 13)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 13)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 14)).Text = "0";
            ((TextBox)this.FindControl("R" + 14)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 14)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 15)).Text = "0";
            ((TextBox)this.FindControl("R" + 15)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 15)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 16)).Text = "0";
            ((TextBox)this.FindControl("R" + 16)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 16)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 17)).Text = "0";
            ((TextBox)this.FindControl("R" + 17)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 17)).CssClass = "blank_center";
            Button_Query_Click(null, null);
        }

        protected void Year0_SelectedIndexChanged(object sender, EventArgs e)
        {
            Button_Plan_In.Visible = false;
            this.Button_Save0.Visible = false;
            ((TextBox)this.FindControl("R" + 1)).Text = "0";
            ((TextBox)this.FindControl("R" + 1)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 1)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 2)).Text = "0";
            ((TextBox)this.FindControl("R" + 2)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 2)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 3)).Text = "0";
            ((TextBox)this.FindControl("R" + 3)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 3)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 4)).Text = "0";
            ((TextBox)this.FindControl("R" + 4)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 4)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 5)).Text = "0";
            ((TextBox)this.FindControl("R" + 5)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 5)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 6)).Text = "0";
            ((TextBox)this.FindControl("R" + 6)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 6)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 7)).Text = "0";
            ((TextBox)this.FindControl("R" + 7)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 7)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 8)).Text = "0";
            ((TextBox)this.FindControl("R" + 8)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 8)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 9)).Text = "0";
            ((TextBox)this.FindControl("R" + 9)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 9)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 10)).Text = "0";
            ((TextBox)this.FindControl("R" + 10)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 10)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 11)).Text = "0";
            ((TextBox)this.FindControl("R" + 11)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 11)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 12)).Text = "0";
            ((TextBox)this.FindControl("R" + 12)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 12)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 13)).Text = "0";
            ((TextBox)this.FindControl("R" + 13)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 13)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 14)).Text = "0";
            ((TextBox)this.FindControl("R" + 14)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 14)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 15)).Text = "0";
            ((TextBox)this.FindControl("R" + 15)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 15)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 16)).Text = "0";
            ((TextBox)this.FindControl("R" + 16)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 16)).CssClass = "blank_center";
            ((TextBox)this.FindControl("R" + 17)).Text = "0";
            ((TextBox)this.FindControl("R" + 17)).ReadOnly = true;
            ((TextBox)this.FindControl("R" + 17)).CssClass = "blank_center";
            Button_Query_Click(null, null);
        }

        //protected void Button_Save0_Click(object sender, EventArgs e)
        //{
        //    SqlConnection Conn = new SqlConnection();
        //    Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
        //    Conn.Open();
        //    SqlCommand Cmd = new SqlCommand();
        //    Cmd.Connection = Conn;
        //    Cmd.CommandText = "if EXISTS(select * from 生产处原辅料计划购进 where 年度=" + this.Year0.SelectedValue + " and 月份=" + this.Month0.Text + " )\n"
        //    + "begin\n"
        //    + "update 生产处原辅料计划购进 set 油管光管计划购进='" + int.Parse(this.R1.Text) + "',套管光管计划购进='" + int.Parse(this.R2.Text) + "',油管接箍管计划购进='" + int.Parse(this.R3.Text) + "',套管接箍管计划购进='" + int.Parse(this.R4.Text) + "',成品接箍计划购进='" + int.Parse(this.R5.Text) + "'\n"
        //    + ",套管螺纹保护环='" + int.Parse(this.R6.Text) + "',油管螺纹保护环='" + int.Parse(this.R7.Text) + "',稀释剂='" + int.Parse(this.R8.Text) + "',油漆='" + int.Parse(this.R9.Text) + "',油品全月支付='" + double.Parse(this.R10.Text) + "'\n"
        //    + " ,打包带='" + int.Parse(this.R11.Text) + "',螺纹脂='" + int.Parse(this.R12.Text) + "',色环漆='" + int.Parse(this.R13.Text) + "',接箍漆='" + double.Parse(this.R14.Text) + "' \n"
        //    + " ,白墨='" + int.Parse(this.R15.Text) + "',草支垫='" + int.Parse(this.R16.Text) + "',其它全月支付='" + double.Parse(this.R17.Text) + "' \n"
        //    + "where 年度='" + this.Year0.SelectedValue + "' and 月份='" + this.Month0.SelectedValue + "'\n"
        //    + "end\n"
        //    + "else\n"
        //    + "begin\n"
        //    + @"insert into 生产处原辅料计划购进 values('" + this.Year0.Text + "','" + this.Month0.Text + "','" + int.Parse(this.R2.Text) + "','" + int.Parse(this.R1.Text) + "','" + int.Parse(this.R3.Text) + "','" + int.Parse(this.R4.Text) + "','" + int.Parse(this.R5.Text) + "','" + int.Parse(this.R6.Text) + "','" + int.Parse(this.R7.Text) + "','" + int.Parse(this.R8.Text) + "','" + int.Parse(this.R9.Text) + "','" + double.Parse(this.R10.Text) + "','" + int.Parse(this.R11.Text) + "','" + double.Parse(this.R12.Text) + "','" + double.Parse(this.R13.Text) + "','" + double.Parse(this.R14.Text) + "','" + int.Parse(this.R15.Text) + "','" + int.Parse(this.R16.Text) + "','" + double.Parse(this.R17.Text) + "')\n"
        //    + "end";
        //    if (Cmd.ExecuteNonQuery() < 1)
        //    {
        //        this.Message.Text = ".保存失败!";
        //    }
        //    else
        //    {
        //        this.Message.Text = ".保存成功!";
        //        this.Button_Plan_In.Visible = false;
        //        this.Button_Save0.Visible = false;
        //        this.R1.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 1)).ReadOnly = true;
        //        this.R2.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 2)).ReadOnly = true;
        //        this.R3.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 3)).ReadOnly = true;
        //        this.R4.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 4)).ReadOnly = true;
        //        this.R5.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 5)).ReadOnly = true;
        //        this.R6.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 6)).ReadOnly = true;
        //        this.R7.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 7)).ReadOnly = true;
        //        this.R8.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 8)).ReadOnly = true;
        //        this.R9.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 9)).ReadOnly = true;
        //        this.R10.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 10)).ReadOnly = true;
        //        this.R11.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 11)).ReadOnly = true;
        //        this.R12.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 12)).ReadOnly = true;
        //        this.R13.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 13)).ReadOnly = true;
        //        this.R14.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 14)).ReadOnly = true;
        //        this.R15.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 15)).ReadOnly = true;
        //        this.R16.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 16)).ReadOnly = true;
        //        this.R17.CssClass = "blank_center";
        //        ((TextBox)this.FindControl("R" + 17)).ReadOnly = true;
        //    }
        //    Conn.Close();
        //    Cmd.Dispose();
        //    Conn.Dispose();
        //    Button_Query_Click(null, null);
        //}

        protected void Button_Plan_In_Click(object sender, EventArgs e)
        {
            //this.R1.CssClass = "textbox";
            //this.R1.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            //((TextBox)this.FindControl("R" + 1)).ReadOnly = false;
            //this.R2.CssClass = "textbox";
            //this.R2.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            //((TextBox)this.FindControl("R" + 2)).ReadOnly = false;
            //this.R3.CssClass = "textbox";
            //this.R3.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            //((TextBox)this.FindControl("R" + 3)).ReadOnly = false;
            //this.R4.CssClass = "textbox";
            //this.R4.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            //((TextBox)this.FindControl("R" + 4)).ReadOnly = false;
            //this.R5.CssClass = "textbox";
            //this.R5.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            //((TextBox)this.FindControl("R" + 5)).ReadOnly = false;
            //this.R6.CssClass = "textbox";
            //this.R6.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            //((TextBox)this.FindControl("R" + 6)).ReadOnly = false;
            //this.R7.CssClass = "textbox";
            //this.R7.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            //((TextBox)this.FindControl("R" + 7)).ReadOnly = false;
            //this.R8.CssClass = "textbox";
            //this.R8.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            //((TextBox)this.FindControl("R" + 8)).ReadOnly = false;
            //this.R9.CssClass = "textbox";
            //this.R9.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            //((TextBox)this.FindControl("R" + 9)).ReadOnly = false;
            this.R10.CssClass = "textbox";
            this.R10.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 10)).ReadOnly = false;
            //this.R11.CssClass = "textbox";
            //this.R11.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            //((TextBox)this.FindControl("R" + 11)).ReadOnly = false;
            //this.R12.CssClass = "textbox";
            //this.R12.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            //((TextBox)this.FindControl("R" + 12)).ReadOnly = false;
            //this.R13.CssClass = "textbox";
            //this.R13.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            //((TextBox)this.FindControl("R" + 13)).ReadOnly = false;
            //this.R14.CssClass = "textbox";
            //this.R14.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            //((TextBox)this.FindControl("R" + 14)).ReadOnly = false;
            //this.R15.CssClass = "textbox";
            //this.R15.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            //((TextBox)this.FindControl("R" + 15)).ReadOnly = false;
            //this.R16.CssClass = "textbox";
            //this.R16.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            //((TextBox)this.FindControl("R" + 16)).ReadOnly = false;
            this.R17.CssClass = "textbox";
            this.R17.BackColor = System.Drawing.Color.FromName("#FFFFF0");
            ((TextBox)this.FindControl("R" + 17)).ReadOnly = false;
        }

    }
}
